#include"comm.hpp"

string TransToHex(key_t k)
{
    char buffer[32];
    snprintf(buffer,sizeof buffer ,"0x%x",k);
    return buffer;
}

int main()
{
    //1.创建通信双方公共的key值
    key_t k = ftok(PATH_NAME,PROJ_ID);
    assert(k!=-1);

    Log("creat key done",Debug)<<"server key:"<<TransToHex(k)<<endl;

    //2.创建共享内存
    int shmid = shmget(k,SHM_SIZE,IPC_CREAT|IPC_EXCL|0666);
    if(shmid == -1)
    {
        perror("shmget");
        exit(1);
    }
    Log("creat shm done",Debug)<<"shmid:"<<shmid<<endl;

    sleep(10);

    //3. 指定共享内存，挂接自己地址
    char*shmaddr = (char*)shmat(shmid,nullptr,0);
    Log("attach shm done",Debug)<<"shmid"<<shmid<<endl;

    sleep(10);
}